# creep class

import common
import random
import pygame 
import effects


class Creep:
    name = ''
    size = [8,8]
    healthmax = 0
    immune = 0
    spawnrate = 40
    img_name = "creep_1"
    money = 2
    x_offset = -size[0]/2
    y_offset = -size[1]/2
    
    def __init__(self,path):
        self.x, self.y = path[0]
        self.speed = 2
        self.health = self.healthmax
        self.image = common.images[self.img_name].copy()
        self.path=path
        self.path_currentpt=1
        self.path_nearrange=10
        self.effects=[]
        self.effect_tick =[]
    def tick(self):
        if self.path_currentpt<len(self.path):        
            a=common.get_angle(self.x-self.path[self.path_currentpt][0],self.y-self.path[self.path_currentpt][1])
            d=common.get_dist_sqr(self.x-self.path[self.path_currentpt][0],self.y-self.path[self.path_currentpt][1])
        
            if d<=(self.speed*2)**2:
                self.path_currentpt+=1
                                
            x,y=common.get_xy(a,self.speed)
            #Turn this into velocity probably. Then we can do some nice stuff with slow effects.
            self.x+=x
            self.y+=y
            
        self.hpPer = (self.health / self.healthmax) * 16.0
        self.hpRect = pygame.Rect(self.x-8,self.y-8, self.hpPer,2)
        
        # effects stuff
        fin_effects = []
        for effect in self.effects:
            effect.tick()
            if effect.time >= effect.length*40:
                 effect.remove()
                 fin_effects.append(effect)
                 
        for effect in fin_effects:
            self.effects.remove(effect)
            
    def shot(self,dmg):
        self.health -= dmg
        
    def effect(self,effect):
        new = True
        for oldeffect in self.effects:
            if oldeffect.etype == 'slow':
                new = False
                break
        if new == True:
            self.effects.append(effect(self))
              
class clvl_1(Creep):
    name = "level 1 creep"
    healthmax = 15.0
    spawnrate = 30
    money = 2
    def __init__(self,pos):
        Creep.__init__(self,pos)
                
class clvl_2(Creep):
    name = "level 2 creep"
    healthmax = 20.0
    spawnrate = 25
    money = 2
    def __init__(self,pos):
        Creep.__init__(self,pos)        
        self.speed = 3
        
class clvl_3(Creep):
    name = "level 3 creep"
    healthmax = 40.0
    spawnrate = 30
    money = 4
    def __init__(self,pos):
        Creep.__init__(self,pos)
        
class clvl_4(Creep):
    name = "level 4 creep"
    healthmax = 60.0
    spawnrate = 30
    money = 4
    def __init__(self,pos):
        Creep.__init__(self,pos)
        self.speed = 3.5
class clvl_5(Creep):
    name = "level 5 creep"
    healthmax = 100.0
    spawnrate = 30
    money = 8
    def __init__(self,pos):
        Creep.__init__(self,pos)
        
class clvl_6(Creep):
    name = "level 6 creep"
    healthmax = 200.0
    spawnrate = 30
    money = 8
    def __init__(self,pos):
        Creep.__init__(self,pos)
        
class clvl_7(Creep):
    name = "level 7 creep"
    healthmax = 300.0
    spawnrate = 20
    money = 12
    def __init__(self,pos):
        Creep.__init__(self,pos)
        
class clvl_8(Creep):
    name = "level 8 creep"
    healthmax = 450.0
    spawnrate = 30
    money = 12
    def __init__(self,pos):
        Creep.__init__(self,pos)
        
class clvl_9(Creep):
    name = "level 9 creep"
    healthmax = 650.0
    spawnrate = 30
    money = 20
    def __init__(self,pos):
        Creep.__init__(self,pos)
                
class clvl_10(Creep):
    name = "level 10 creep"
    healthmax = 1000.0
    spawnrate = 35
    money = 20
    def __init__(self,pos):
        Creep.__init__(self,pos)
                 
clist = [clvl_1,clvl_2,clvl_3,clvl_4,clvl_5,clvl_6,clvl_7,clvl_8,clvl_9,clvl_10]